# -*- coding: utf-8 -*-
# @Time : 2021/7/2 21:07
# @Author : feimaotuiya
# @File : page_ecshop_front_search_goods.py
# @Project : ecshop-gitee
from selenium.webdriver.common.by import By


class PageEcshopFrontSearchGoods():
    '''前台搜索商品'''
    def __init__(self, driver):
        self.driver = driver
        # 元素定位
        self.loc_front_search_goods_keyword = (By.NAME, 'keywords')
        self.loc_front_search_goods_name = (By.NAME, 'imageField')
        self.loc_front_search_assert = (By.XPATH, '/html/body/div[7]/div[2]/div[1]/div/h3/span')
        self.loc_front_search_assert_res = (By.XPATH, '//form[@id="compareForm"]/div/div[1]/p/a')

    def front_search_goods_keyword(self, keyword):  # 输入搜索内容
        self.driver.find_element(*self.loc_front_search_goods_keyword).send_keys(keyword)

    def front_search_goods_name(self):  # 点击搜索
        self.driver.find_element(*self.loc_front_search_goods_name).click()

    def front_search_assert(self):  # 断言 结果
        actual = self.driver.find_element(*self.loc_front_search_assert).text
        return actual

    def front_search_assert_res(self):  # 断言 搜索结果的第一条的商品名
        actual = self.driver.find_element(*self.loc_front_search_assert_res).text
        return actual

    def search(self, keyword):
        self.front_search_goods_keyword(keyword)
        self.front_search_goods_name()
        actual = self.front_search_assert()
        return actual

    def search_res(self, keyword):
        self.front_search_goods_keyword(keyword)
        self.front_search_goods_name()
        actual = self.front_search_assert_res()
        return actual
